package com.zhaohanlin.start;

import org.junit.Test;

import java.util.Arrays;
import java.util.Random;

/**
 * @author zhaohanlin
 */

public class TestText {
    @Test
    public void add() {
        System.out.println(10 / 4);
        System.out.println(10.0 / 4);
        System.out.println(0 % 3);
        System.out.println(-5 % 3);
        System.out.println(5 % 3);
        int i = 100;
        i = i++;
        System.out.println(i);
        int a = 1;
        System.out.println(a += 5);
        System.out.println(a -= 5);
        System.out.println(a /= 5);
        System.out.println(a %= 5);
    }

    @Test
    public void add1() {
        int a = 10;
        System.out.println(a > 11);
        System.out.println(a < 11);
        System.out.println(a == 11);
        System.out.println(a != 11);
        System.out.println(a <= 11);
        System.out.println(a >= 11);
    }

    @Test
    public void add2() {
        int a = 7;
        System.out.println(a < 9 && a == 7);
        System.out.println(a < 9 || a == 7);
        System.out.println(!(a == 9));
        System.out.println(a == 9 || a == 8 && a == 7);

    }

    @Test
    public void bit() {
        int a = 10;
        // 位运算不会发生短路现象
        System.out.println(a != 10 & a++ == 10);
        System.out.println(a);
    }

    /**
     * 需求：及格60以上，不及格60以下，优秀80以上
     */
    @Test
    public void add3() {
        double a = 60.5;
        String result = a >= 80 ? "优秀" : (a >= 60 ? "及格" : "不及格");
        System.out.println(result);
    }

    @Test
    public void mathApi() {
        System.out.println(Math.max(1, 2));
        System.out.println(Math.min(1, 2));
        System.out.println(Math.ceil(1.1));
        System.out.println(Math.floor(1.9));
        System.out.println(Math.abs(-5));
        System.out.println(Math.pow(2, 3));
        System.out.println(Math.round(-11.5));
    }

    @Test
    public void boxing() {
        Byte by = 100;
        Short sh = 200;
        Integer in = 300;
        Long lo = 400L;
        Double dou = 3.5;
        Float fl = 3.6F;
        Boolean flag = true;
        Character ch = '5';

        System.out.println(by);
        System.out.println(sh);
        System.out.println(in);
        System.out.println(lo);
        System.out.println(dou);
        System.out.println(fl);
        System.out.println(flag);
        System.out.println(ch);
    }

    /**
     * 自动拆箱
     */
    @Test
    public void unBoxing() {
        // A a = new A();
        Integer integer = new Integer(129);
        int result = integer;
        System.out.println(result);


    }

    @Test
    public void add5() {
        int sum = 0;
        for (int i = 1; i <= 5; i++) {
            sum += i;

        }
        System.out.println(sum);

    }

    @Test
    public void add6() {
        int i = 100;
        int sum = 0;
        do {

            System.out.println(i);
            i++;
        } while (i <= 10);

    }

    @Test
    public void add7() {
        for (int i = 1; i < 10; i++) {
            if (i == 3) {
                continue;

            }
            System.out.println("循环到了" + i);
        }
    }

    /**
     * break结束当前它所在的循环
     * 需求：判断100-200之间有没有能被23整除的数。
     */
    @Test
    public void add8() {
        String result = "没有";
        for (int i = 100; i <= 200; i++) {
            if (i % 201 == 0) {
                result = "有";
                break;
            }
        }
        System.out.println(result);
    }

    @Test
    public void add9() {
        int[][] arrA = {
                {1, 2, 3, 4},
                {156, 145, 487},
                {15, 16, 78}
        };

        for (int[] e : arrA) {
            for (int i : e) {
                System.out.println(i + "\t");
            }
            System.out.println();
        }
    }

    @Test
    public void add10() {
        int[] arrA = {1, 2314, 123};
        System.out.println(arrA[0]);
        System.out.println(arrA[1]);
        System.out.println(arrA[2]);

        // 仅指定长度
        int[] arrB = new int[3];
        arrB[0] = 1;
        arrB[1] = 2314;
        System.out.println(arrB[0]);
        System.out.println(arrB[1]);
        System.out.println(arrB[2]);
        int[] arrC = {1, 2314, 123};
        System.out.println(arrC);
        char[] arrD = {'h', 'i'};
        System.out.println(arrD);
        System.out.println("char数组内存地址：" + arrD.toString());
    }

    @Test
    public void oneArrayTraverse() {

        int[] arrA = {1, 2314, 123};

        // 数组.length 返回数组中有多少个元素
        // 利用普通的for循环进行遍历
        for (int i = 0, j = arrA.length; i < j; i++) {
            System.out.println(arrA[i]);
        }
        for (int e : arrA) {
            System.out.println(e);
        }
        System.out.println(Arrays.toString(arrA));
    }
}

